
package com.platform.common.filter;

import com.platform.common.core.Result;
import com.platform.common.util.rest.ResponseUtils;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.FilterConfig;
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;

/**
 * 异常过滤器
 * @author guoyunfei
 */
@Slf4j
public class ExceptionHandlerFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain){
        try {
            filterChain.doFilter(servletRequest, servletResponse);
        } catch (Exception e) {
            log.error("异常过滤器：{}",e.getMessage());
            ResponseUtils.out((HttpServletResponse) servletResponse, Result.failure(e.getMessage()));
        }
    }

    @Override
    public void destroy() {

    }
}
